﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IBLL;
using MisDLL;
using System.Data;

namespace MisBLL
{
    public class DayJSDAO : MarshalByRefObject, IDayJS
    {
        protected DbHelper dbHelper = new DbHelper();

        //根据编码查询客户结算周期信息
        public MisModel.DayJs GetById(string id)
        {
            if (string.IsNullOrEmpty(id))
                return null;
            string sql = string.Format("select * from DayJs_TAB where DAY_JS='{0}'", id);
            DataTable dt=  dbHelper.ExecuteDataTable(sql);
            MisModel.DayJs entity = null;
            if (dt != null && dt.Rows.Count > 0){
                entity = new MisModel.DayJs();
                entity.DayJS = int.Parse(dt.Rows[0]["DAY_JS"].ToString());
                entity.F1 = dt.Rows[0]["F1"].ToString();
            }
            return entity;
        }

        //查询客户结算周期列表
        public DataTable GetAll()
        {
            string sql = "select DAY_JS,F1,(str(DAY_JS) + '.' + F1) as ItemShow  from DayJs_TAB";
            return dbHelper.ExecuteDataTable(sql);
        }

        //添加客户结算周期信息
        public int Add(MisModel.DayJs obj)
        {
            if (string.IsNullOrEmpty(obj.F1.ToString()))
            {
                obj.F1 = "Y";
            }
            string sql = string.Format("insert into DayJs_TAB(DAY_JS,F1) values('{0}','{1}')", obj.DayJS, obj.F1);
            return dbHelper.ExecuteNonQuery(sql);
        }

        //修改客户结算周期信息
        public int Update(MisModel.DayJs obj)
        {
            string sql = string.Format("update DayJs_TAB set F1='{1}' where DAY_JS='{2}'", obj.F1, obj.DayJS);
            return dbHelper.ExecuteNonQuery(sql);
        }

        //根据ID删除客户结算周期信息
        public int Delete(string id)
        {
            string sql = string.Format("delete from DayJs_TAB where DAY_JS='{0}'", id);
            return dbHelper.ExecuteNonQuery(sql);
        }
    }
}
